package com.servertest1;

import java.net.InetAddress;
import java.net.Socket;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

public class Client
{
	private Socket socket;
	private ObjectOutputStream oos;
	private ObjectInputStream ois;
		
	public Client()
	{
		socket = null;
		oos = null;
		ois = null;
	}

	public void close()
	{
		try
		{
			oos.close();
			ois.close();
			socket.close();
		}
		catch(Exception e)
		{
			System.out.println(e);
		}
	}

	public void connect()
	{
		try{
			//socket = new Socket("192.168.1.69", 52200);// Brett's home
			//socket = new Socket("192.168.1.104", 52200);// Brett's Computer
			//socket = new Socket("192.168.1.105", 63200); // Devon's Computer
			//socket = new Socket("192.168.1.103", 52200); // Dan's Computer
			socket = new Socket("128.105.24.183", 52200); // Computer Science
			//socket = new Socket("72.33.128.12", 52200); /Brett/ Wendt Library
			//socket = new Socket("127.0.0.1", 52200); //Local Host
			//socket = new Socket("10.140.2.108", 52200); //Discovery Building
		}
		catch(Exception e){
			System.err.println(e.toString());
			e.printStackTrace();
		}
	}	
	
	public void sendData(String[] data){
		// Send data
		try {
			oos = new ObjectOutputStream(socket.getOutputStream());
			oos.writeObject(data);
		} catch (IOException e1) {
			e1.printStackTrace();
		}
		
		
	}
	
	public String[] recieveData(){
		String[] message;
		try {
			ois = new ObjectInputStream(socket.getInputStream());
			message = (String[])ois.readObject();
		} catch (Exception e) {
			message = new String[1];
			message[0] = "ERROR-Client.java";
			e.printStackTrace();
			System.err.println("No data received");
		}
		
		return message;
	}	
}
